import java.util.Scanner;

public class Main1714 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        for (int i=1;i<=n;i++){
            int a=i/1000;//
            int b=i/100%10;//2
            int c=i%100/10;//3
            int d=i%100%10;//4
            if (a==3||b==3||c==3||d==3||a==5||b==5||c==5||d==5){
                if (i%2==0){
                    System.out.println(i);
                }
            }
        }
    }
}
